Ext.define('DragonApp.view.base.Controller', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.base',

    requires: [
        'DragonApp.util.Msg'
    ],
    /**
     * 提交查询请求
     *
     * @param    object button 提交按钮
     * @param    {[type]} e [description]
     * @param    {[type]} options [description]
     * @return   {[type]}
     */
    onSubmitClick: function(button, e, options) {

        var me = this;

        var form = this.getView().getForm();

        if (!form.isValid()) return;

        var formValue = form.getValues();

        var grid = Ext.ComponentQuery.query('basegrid',button.up('Container'))[0];
        var store = grid.getStore();


        //根据查询附加参数加载数据仓库

        store.load({
            params: formValue,
            scope: this,
            callback: function(records, operation, success) {

                if (success == false) {
                    store.removeAll();
                }
            }
        });
    },

    onTextFieldSpecialKey: function(field, e, options) {
        if (e.getKey() === e.ENTER) {
            if (this.getView().getForm().isValid()) {
                this.onSubmitClick();
            }
        }
    },
    //============
    //内容提示渲染
    //============
    attrRender: function(value, metadata, record, rowIndex, columnIndex, store) {

        var register = record.get('register');
        var rtn;

        if(value === null){
            rtn = null;
        }else if(Ext.isEmpty(register)){
            rtn = null;
        }else{
            rtn = Ext.util.Format.number((value/register)*100, '0.00%');
        }


        var map = [];

        map[4] = 'RET2';
        map[5] = 'RET3';
        map[6] = 'RET4';
        map[7] = 'RET5';
        map[8] = 'RET6';
        map[9] = 'RET7';
        map[10] = 'RET15';
        map[11] = 'RET30';

        var rec= store.getAt ( rowIndex ) ;
        var data = rec.getData();

        var v = data[map[columnIndex]];
        if(null===v){
            v = 0;
        }
        if (typeof(rtn) == "undefined") {
            rtn = '';
            metadata.tdAttr = 'data-qtip="' + v + '" ' + 'data-qalign="bl-br"' + 'data-qwidth="auto"';
            return rtn;
        } else {
            metadata.tdAttr = 'data-qtip="' + v + '" ' + 'data-qalign="bl-br"' + 'data-qwidth="auto"';
            return rtn;
        }
    }
});